package com.luobo.structure.adapter;

import com.luobo.structure.adapter.basics.SimplePlayer;
import com.luobo.structure.adapter.basics.SuperPlayer;
import com.luobo.structure.adapter.basics.Mp4Player;
import com.luobo.structure.adapter.basics.MvPlayer;

/**
 * 23种设计模式之:适配器模式
 * 多媒体适配器
 * 将一个类的接口转换成客户希望的另外一个接口。适配器模式使得原本由于接口不兼容而不能一起工作的那些类可以一起工作。
 */
public class MediaAdapter implements SimplePlayer {

    private SuperPlayer superPlayer;

    public MediaAdapter(String audioType){
        if(audioType.equalsIgnoreCase("mv") ){
            superPlayer = new MvPlayer();
        } else if (audioType.equalsIgnoreCase("mp4")){
            superPlayer = new Mp4Player();
        }
    }

    @Override
    public void play(String audioType, String fileName) {
        if(audioType.equalsIgnoreCase("mv")){
            superPlayer.playMv(fileName);
        }else if(audioType.equalsIgnoreCase("mp4")){
            superPlayer.playMp4(fileName);
        }
    }
}
